package com.jiapu.controller;

import com.jiapu.common.Result;
import com.jiapu.entity.People_information;
import com.jiapu.mapper.People_informationMapper;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController

@RequestMapping("/people")
public class People_informationController {

    @Resource
    People_informationMapper people_informationMapper;

    @GetMapping("/total")
    public int getTotalCount() {
        return people_informationMapper.getTotalCount();
    }

    @GetMapping("/list")
    public Result getPeopleList(@RequestParam("currentPage") int currentPage, @RequestParam("pageSize") int pageSize) {
        int offset = (currentPage - 1) * pageSize;
        return  Result.success(people_informationMapper.getPeopleInformation(offset, pageSize));
    }

    @GetMapping("/search")
    public Result list(@RequestParam(value="search") String people_name){
        List<People_information> people_informationSearchList = people_informationMapper.search(people_name);
        return Result.success(people_informationSearchList);
    }

    @PostMapping
    public Result addPeople_information(@RequestBody People_information people_information){
        people_informationMapper.savep(people_information);
        return Result.success();
    }

    @PutMapping
    public String updatePeople_information(@RequestBody People_information people_information){
        people_informationMapper.updateByIdp(people_information);
        return "success";
    }


    @PutMapping("/del")
    public String deletePeople_information(@RequestBody People_information people_information){
        people_informationMapper.deleteByIdp(people_information);
        return "success";
    }
}
